var DATA = '%data%';

var bio = {
  name: 'Li Jing',
  role: 'Java Software Engineer',
  contacts: {
    mobile: '+86 17610282721',
    email: '641090980@qq.com',
    github: 'https://gitee.com/ly_you',
    twitter: 'null',
    location: 'Beijing,China'
  },
  welcomeMessage: 'Software Engineer based in Beijing, China. Mainly focused on Java web application development.',
  skills: ['C', 'C++', 'Java', 'Linux shell', 'redis', 'Mysql', 'Spring MVC'],
  biopic: 'images/me.jpeg',
  display: function() {
    var formattedName = HTMLheaderName.replace(DATA, bio.name);
    var formattedRole = HTMLheaderRole.replace(DATA, bio.role);

    var formattedMobile = HTMLmobile.replace(DATA, bio.contacts.mobile);
    var formattedEmail = HTMLemail.replace(DATA, bio.contacts.email);
    var formattedGithub = HTMLgithub.replace(DATA, bio.contacts.github);
    var formattedTwitter = HTMLtwitter.replace(DATA, bio.contacts.twitter);
    var formattedLocation = HTMLlocation.replace(DATA, bio.contacts.location);

    var formattedBioPic = HTMLbioPic.replace(DATA, bio.biopic);
    var formattedWelcomeMessage = HTMLwelcomeMsg.replace(DATA, bio.welcomeMessage);

    $('#header').prepend(formattedName + formattedRole);
    $('#topContacts, #footerContacts').append(formattedMobile + formattedEmail +
      formattedGithub + formattedTwitter + formattedLocation);
    $('#header').append(formattedBioPic);
    $('#header').append(formattedWelcomeMessage);

    if (bio.skills.length > 0) {
      $('#header').append(HTMLskillsStart);

      for (var i = 0, len = bio.skills.length; i < len; i++) {
        var formattedSkills = HTMLskills.replace(DATA, bio.skills[i]);

        $('#skills').append(formattedSkills);
      }
    }
  }
};

var education = {
  schools: [
    {
      'name': 'Dalian University of Technology',
      'location': 'Ganjingzi District, Dalian City, Liaoning Province, P.R.C.',
      'degree': 'Bachelor of Computer (BSc.), Computer Science And Technology',
      'majors': ['Computer Science And Technology'],
      'dates': '2013 - 2017',
      'url': 'http://www.dlut.edu.cn'
    }
  ],
  onlineCourses: [
   {
     'title': 'Front-end',
     'school': 'Udacity',
     'dates': 'August 2017',
     'url': 'https://www.udacity.com'
   },
   {
     'title': 'Python for Beginners',
     'school': 'Udacity',
     'dates': 'July 2017',
     'url': 'https://www.udacity.com'
   }
  ],
  display: function() {
    if (education.schools.length > 0 || education.onlineCourses.length > 0) {
      for (var i = 0, iLen = education.schools.length; i < iLen; i++) {
        var formattedName = HTMLschoolName.replace(DATA, education.schools[i].name);
        var formattedDegree = HTMLschoolDegree.replace(DATA, education.schools[i].degree);
        var formattedSchoolDates = HTMLschoolDates.replace(DATA, education.schools[i].dates);
        var formattedLocation = HTMLschoolLocation.replace(DATA, education.schools[i].location);
        var formattedNameDegree = formattedName + formattedDegree;

        $('#education').append(HTMLschoolStart);
        $('.education-entry:last').append(formattedNameDegree);
        $('.education-entry:last').append(formattedSchoolDates);
        $('.education-entry:last').append(formattedLocation);

        for (var j = 0, jLen = education.schools[i].majors.length; j < jLen; j++) {
          var formattedMajor = HTMLschoolMajor.replace(DATA, education.schools[i].majors[j]);

          $('.education-entry:last').append(formattedMajor);
        }
      }

      $('#education').append(HTMLonlineClasses);

      for (var k = 0, len = education.onlineCourses.length; k < len; k++) {
        var formattedTitle = HTMLonlineTitle.replace(DATA, education.onlineCourses[k].title).replace('#', education.onlineCourses[k].url);
        var formattedSchool = HTMLonlineSchool.replace(DATA, education.onlineCourses[k].school);
        var formattedOnlineDates = HTMLonlineDates.replace(DATA, education.onlineCourses[k].dates);
        var formattedUrl = HTMLonlineURL.replace(DATA, education.onlineCourses[k].url);
        var formattedTitleSchool = formattedTitle + formattedSchool;

        $('#education').append(HTMLschoolStart);
        $('.education-entry:last').append(formattedTitleSchool);
        $('.education-entry:last').append(formattedOnlineDates);
        $('.education-entry:last').append(formattedUrl);
      }
    }
  }
};

var work = {
  jobs: [
    {
      employer: 'IQianJin(Beijing) Information Technology Co.,Ltd.',
      title: 'Java Software Engineer',
      location: 'Beijing,China',
      dates: 'December 2016 - Until now',
      description: 'I work in IQianJin that focuses on big data processing ' +
                   'and financial technology research and development, provide ' +
                   'individuals with more efficient and intelligent financial ' +
                   'services and solutions, use technology to shorten the distance ' +
                   'between people and financial services, promote equalization of ' +
                   'financial services, and strive to practice inclusive finance.'
    },
    {
      employer: 'Dalian Wenhai Sichuang Information Technology Co., Ltd.',
      title: 'Android Software Intern',
      location: 'Dalian,China',
      dates: 'June 2016 - September 2016',
      description: 'I work in this company for improving my program skills.'
    }

  ],
  display: function() {
    if (work.jobs.length > 0) {
      for (var i = 0, len = work.jobs.length; i < len; i++) {
        var formattedEmployer = HTMLworkEmployer.replace(DATA, work.jobs[i].employer);
        var formattedTitle = HTMLworkTitle.replace(DATA, work.jobs[i].title);
        var formattedDates = HTMLworkDates.replace(DATA, work.jobs[i].dates);
        var formattedLocation = HTMLworkLocation.replace(DATA, work.jobs[i].location);
        var formattedDescription = HTMLworkDescription.replace(DATA, work.jobs[i].description);
        var formattedEmployerTitle = formattedEmployer + formattedTitle;

        $('#workExperience').append(HTMLworkStart);
        $('.work-entry:last').append(formattedEmployerTitle);
        $('.work-entry:last').append(formattedDates);
        $('.work-entry:last').append(formattedLocation);
        $('.work-entry:last').append(formattedDescription);
      }
    }
  }
};

var projects = {
  projects: [
    {
      title: 'Android Sudoku Game App',
      dates: 'September 2015-October 2016',
      description: 'The project includes a game module, a user information ' +
                   'storage module, a difficulty selection module, and an option ' +
                   'setting module, which realizes the functions of the Sudoku ' +
                   'game and the target app runs on the Android client.',
      images: ['images/sudoku.jpeg']
    },
    {
      title: 'Smart toothbrush',
      dates: 'November 2014-June 2016',
      description: 'This system realizes the interactive function of the toothbrush ' +
                   'and mobile terminal and is divided into hardware and software. ' +
                   'The hardware is the design of the toothbrush internal single-chip ' +
                   'microcomputer program and circuit board, and the software is the ' +
                   'program in the single-chip microcomputer and the implementation ' +
                   'of the mobile terminal App. The sensor collects the user\'s ' +
                   'brushing data information and uploads it to the mobile terminal, ' +
                   'giving the user a visual and intelligent brushing experience.',
      images: ['images/smart_toothbrush.jpg']
    },
    {
      title: 'Pattern Lock App',
      dates: 'September 2015',
      description: 'A small app that can lock or unlock mobile phone with pattern.',
      images: ['images/pattern.jpg']
    },
    {
      title: 'Activity backStage Manage System',
      dates: 'September 2017',
      description: 'A web application that provides methods and resources for operation colleague to manage online activities.',
      images: []
    },
    {
      title: 'App Member System',
      dates: 'August 2017',
      description: 'A web application that calculate user\'s member informations, such its level, create time, expire time etc.',
      images: []
    }
  ],
  display: function() {
    if (projects.projects.length > 0) {
      for (var i = 0, iLen = projects.projects.length; i < iLen; i++) {
        var formattedTitle = HTMLprojectTitle.replace(DATA, projects.projects[i].title);
        var formattedDates = HTMLprojectDates.replace(DATA, projects.projects[i].dates);
        var formattedDescription = HTMLprojectDescription.replace(DATA, projects.projects[i].description);

        $('#projects').append(HTMLprojectStart);
        $('.project-entry:last').append(formattedTitle);
        $('.project-entry:last').append(formattedDates);
        $('.project-entry:last').append(formattedDescription);

        for (var j = 0, jLen = projects.projects[i].images.length; j < jLen; j++) {
          var formattedImage = HTMLprojectImage.replace(DATA, projects.projects[i].images[j]);

          $('.project-entry:last').append(formattedImage);
        }
      }
    }
  }
};

bio.display();
education.display();
work.display();
projects.display();
$('#mapDiv').append(googleMap);

